<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <div class="filter-item" style="margin-right:20px;">
        <span class="txt">推荐：</span>
        <el-radio-group v-model="search.status">
          <el-radio :label="-1">全部</el-radio>
          <el-radio :label="0">是</el-radio>
          <el-radio :label="1">否</el-radio>
        </el-radio-group>
      </div>
      <el-input class="filter-item" @keyup.enter.native="handleFilter" style="width: 200px;" placeholder="请输入关键词" v-model="search.keyword"></el-input>
      <el-button class="filter-item" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table v-loading="!pload" ref="multipleTable" border :data="tableData">
      <el-table-column property="roomNo" label="直播间号" show-overflow-tooltip></el-table-column>
      <el-table-column property="contentText" label="消息内容" show-overflow-tooltip></el-table-column>
      <el-table-column property="fromUserName" label="发布者" show-overflow-tooltip></el-table-column>
      <el-table-column property="url" label="发言时间" show-overflow-tooltip width="200">
        <template slot-scope="scope">
          <span>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="limit" :page-sizes="limits" background layout="sizes, prev, pager, next, jumper, total" :total="count">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import * as api from '@/utils/api'
import waves from '@/directive/waves' // 水波纹指令
export default {
  directives: {
    waves
  },
  data() {
    return {
      tableData: [],
      search: {
        keyword: '',
        status: -1
      },
      pload: false,
      currentPage: 1,
      limit: 10,
      limits: [10, 20, 50, 100],
      count: 0
    }
  },
  computed: {
    roomId() {
      return this.$route.query.id
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async handleDel(index, row) {
      this.$confirm('确认要删除吗', { type: 'warning' }).then(async() => {
        try {
          this.pload = false
          await api.delZBmsg({ ids: row.messageId })
          this.$notify({ title: '操作成功', type: 'success', duration: 5000 })
          this.getData()
        } catch (e) {
          this.pload = true
        }
      })
    },
    async getData() {
      const data = { pageNum: this.currentPage, pageSize: this.limit, ...this.search, roomId: this.roomId, type: 1 }
      this.pload = false
      const Datas = await api.getZBmsgList(data)
      this.tableData = Datas.list
      this.count = Datas.total
      this.pload = true
    },
    handleFilter() {
      this.currentPage = 0
      this.getData()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.limit = val
      this.getData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getData()
    }
  }
}
</script>
